<?php
/**
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file license.txt or that can be found at 
 * http://code.google.com/p/billboardce/wiki/License.
 *
 * @package    Slidetype_FLV
 * @category   Slide Type
 * @license    http://code.google.com/p/billboardce/wiki/License New BSD License
 * @version    SVN: $Id: $
 */
class Slidetype_FLV extends Bbce_Slidetype_Abstract
{
    /**
     * Title of the plugin, as shown in the interface
     * 
     * @var string
     */
    protected $_title = 'FLV Video URL';
    
    /**
     * Description of the plugin, as shown in the interface
     * 
     * @var string
     */
    protected $_description = 'URL to an Flash video.';
    
    /**
     * Builds the slide requested.  Returns an associative
     * array of key => value pairs of variables to be assigned
     * to the view object.
     * 
     * Example:  return array('url' => 'http://www.google.com');
     * 
     * This will assign the value of "http://www.google.com" to the view
     * variable "url".  In the view, you will access this by "echo $this->url";
     * 
     * @param int $slideId
     * @return array
     */
    public function buildSlide($slideId)
    {
        $thisSlide = $this->find($slideId);
       
        return array(
            'url'    => $thisSlide['url'],
            'mute'   => $thisSlide['mute'],
            'volume' => $thisSlide['volume'],
        );
    }
    
    /**
     * Generates a thumbnail for the given slide.
     * 
     * @param $slideId
     * @return PHPGD image object
     */
    public function generateSlideThumbnail($slideId)
    {
        $path = realpath(APPLICATION_PATH . '/../loadable/slidetype/FLV/FlashVideo.png');

        return imagecreatefrompng($path);
    }       
    
    /**
     * Generates a Zend_Form object which is displayed when
     * editing the given slide type.  The $values array is
     * a key => value associative array that maps the form
     * field names with their default values, if any.
     * 
     * @param array $values
     * @return object Zend_Form
     */
    public function getConfigurationForm($values = array())
    {
        $form = new Zend_Form();
        $form->setAttrib('class', 'slideTypeForm')
             ->setDecorators(array(
                     'FormElements',
                     array('HtmlTag', array('tag' => 'div', 'class' => 'zend_form')),
                     'Form'
             ));
             
        $url = $form->createElement('text', 'url', array('label' => 'Url:'));
        $url->setValue(isset($values['url']) ? $values['url'] : '');
        
        $mute = $form->createElement('select', 'mute', array('label' => 'Mute Video:'));
        $mute->setMultiOptions(array(
                '0' => 'No',
                '1' => 'Yes'
               ))
             ->setValue(isset($values['mute']) ? $values['mute'] : '0');
             
        $volume = $form->createElement('select', 'volume', array('label' => 'Volume:'));
        
        for ($x = 0; $x <= 100; $x+=5) {
            $volume->addMultiOption($x, $x);
        }
        
        $volume->setValue(isset($values['volume']) ? $values['volume'] : '75');
        
        $form->addElements(array($url, $mute, $volume));

        $form->setElementDecorators(array(
                  'ViewHelper',
                  'Errors',
                  array('HtmlTag', array('tag' => 'div', 'class' => 'elm')),
                  array('Label', array('tag' => 'span')),
              ));
        
        return $form;      
    }        
}